




*------------------------------------------------------------------------------
*  Dynamics in individual-level attitudes on federal and provincial level
*------------------------------------------------------------------------------



//Land
putexcel set "tables\dynamic_lazarsfeld_spd.xlsx", sheet(Land) replace

putexcel A2 = "Andere Partei"
putexcel A3 = "SPD: Loyal"
putexcel A4 = "SPD: Parteiwechsel"
putexcel A5 = "SPD: Kristallisation"
putexcel A6 = "SPD: Schwankend"


putexcel B1 = "Partei -"
putexcel C1 = "Partei 0"
putexcel D1 = "Partei +"
putexcel E1 = "Kandidat -"
putexcel F1 = "Kandidat 0"
putexcel G1 = "Kandidat +"
putexcel H1 = "N"


//Formatting
putexcel A1:A6, right border(right double) overwritefmt
putexcel B1:H1,  bold  overwritefmt


//Candidates: Export distribution to Excel
local zeile = 1
foreach laztype2017_spd of numlist 0/4  {
	local zeile = `zeile' + 1
		fre	ckat_welec_L_scalspdall		if laztype2017_spd == `laztype2017_spd'
		putexcel B`zeile' = matrix(r(valid)'/r(N_valid)), nformat(percent)
		fre	ckat_welec_L_candspdall if laztype2017_spd == `laztype2017_spd'
		putexcel E`zeile' = matrix(r(valid)'/r(N_valid)), nformat(percent)
		putexcel H`zeile' = `r(N_valid)'
}

//Bund
putexcel set "tables\dynamic_lazarsfeld_spd.xlsx", sheet(Bund) modify

putexcel A2 = "Andere Partei"
putexcel A3 = "SPD: Loyal"
putexcel A4 = "SPD: Parteiwechsel"
putexcel A5 = "SPD: Kristallisation"
putexcel A6 = "SPD: Schwankend"


putexcel B1 = "Partei -"
putexcel C1 = "Partei 0"
putexcel D1 = "Partei +"
putexcel E1 = "Kandidat -"
putexcel F1 = "Kandidat 0"
putexcel G1 = "Kandidat +"
putexcel H1 = "N"


//Formatting
putexcel A1:A6, right border(right double) overwritefmt
putexcel B1:H1,  bold  overwritefmt


//Candidates: Export distribution to Excel
local zeile = 1
foreach laztype2017_spd of numlist 0/4  {
	local zeile = `zeile' + 1
		fre	ckat_welec_B_scalspdall		if laztype2017_spd == `laztype2017_spd'
		putexcel B`zeile' = matrix(r(valid)'/r(N_valid)), nformat(percent)
		fre	ckat_welec_B_candspdall if laztype2017_spd == `laztype2017_spd'
		putexcel E`zeile' = matrix(r(valid)'/r(N_valid)), nformat(percent)
		putexcel H`zeile' = `r(N_valid)'
}



tab2 ckat_welec_L_scalspdall	laztype2017_spd, col
tab2 ckat_welec_B_scalspdall	laztype2017_spd, col

